package com.example.recyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Imagetext> imagetextList=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        android.support.v7.widget.RecyclerView recyclerView=(android.support.v7.widget.RecyclerView)findViewById(R.id.recycle_view);
        //LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        //横向
        //layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //网格
        GridLayoutManager layoutManager=new GridLayoutManager(this,3);
        //分割线设置
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));
        recyclerView.setLayoutManager(layoutManager);
        RecyclerViewAdapter adapter=new RecyclerViewAdapter(imagetextList);
        recyclerView.setAdapter(adapter);
    }
    private void init(){
        Imagetext a=new Imagetext("aaa",R.mipmap.ic_launcher);
        imagetextList.add(a);
        Imagetext b=new Imagetext("aaa",R.mipmap.ic_launcher);
        imagetextList.add(b);
        Imagetext c=new Imagetext("aaa",R.mipmap.ic_launcher);
        imagetextList.add(c);
        Imagetext d=new Imagetext("aaa",R.mipmap.ic_launcher);
        imagetextList.add(d);
        Imagetext e=new Imagetext("aaa",R.mipmap.ic_launcher);
        imagetextList.add(e);
        Imagetext f=new Imagetext("aaa",R.mipmap.ic_launcher);
        imagetextList.add(f);
    }
}
